package com.xbongbong.saas.model;

import com.alibaba.fastjson.JSONObject;
import com.xbongbong.aiassistant.domain.entity.AiPurchaseEntity;
import com.xbongbong.paas.toolbox.exception.XbbException;
import com.xbongbong.paas.toolbox.wrap.IModel;
import com.xbongbong.pro.businessdata.pojo.dto.FormatExplainDTO;
import com.xbongbong.pro.domain.entity.UpdateDataEntity;
import com.xbongbong.pro.formdata.pojo.dto.SaasAnalysisDataDTO;
import com.xbongbong.saas.domain.entity.PurchaseProductEntity;
import com.xbongbong.saas.domain.entity.ext.ProductEntityExt;
import com.xbongbong.saas.domain.entity.ext.PurchaseEntityExt;
import com.xbongbong.saas.enums.UpdateDataTypeEnum;
import org.elasticsearch.action.support.WriteRequest;

import java.util.List;
import java.util.Map;
/**
 * 采购合同
 * @author Jian.Wang
 * @date 2019/1/29 20:38
 * @since v1.0
 * @version v1.0
 */
public interface PurchaseModel extends IModel<PurchaseEntityExt> {
    /**
     * 采购合同数据插入
     * @param entity 供应商实体
     * @author Jian.Wang
     * @date 2019/1/23 20:27
     * @since v1.0
     * @throws XbbException 异常
     * @return Integer
     */
    @Override
    Integer insert(PurchaseEntityExt entity) throws XbbException;
    /**
     * 采购合同数据更新
     * @param entity 供应商实体
     * @author Jian.Wang
     * @date 2019/1/23 20:27
     * @since v1.0
     * @throws XbbException 异常
     * @return Integer
     */
    @Override
    Integer update(PurchaseEntityExt entity) throws XbbException;
    /**
     * 采购合同数据查询多个
     * @param param 参数
     * @author Jian.Wang
     * @date 2019/1/23 20:27
     * @since v1.0
     * @return List
     */
    @Override
    List<PurchaseEntityExt> findEntitys(Map<String, Object> param);

    /**
     * 采购合同数据单条查询
     * @param key 主键ID
     * @param corpid 公司ID
     * @author Jian.Wang
     * @date 2019/1/23 20:27
     * @since v1.0
     * @return Integer
     */
    PurchaseEntityExt getByKey(Long key, String corpid);


    /**
     * 保存
     * @param purchase 采购合同保存
     */
    Integer save(PurchaseEntityExt purchase) throws XbbException;

    /**
     * 更新数据
     * @author 吴峰
     * @date 2019/3/4 23:21
     * @param list
     * @param corpid
     * @return java.lang.Integer
     * @throws XbbException 业务异常
     */
    Integer updateBatch(List<UpdateDataEntity> list, String corpid) throws XbbException;

    Integer updateBatch(List<UpdateDataEntity> updateList, String corpid,boolean needThrow) throws XbbException;
    /**
     * 批量编辑
     * @author 吴峰
     * @date 2020/6/15 11:04
     * @param updateList 更新数据
     * @param corpid 公司id
     * @return
     * @throws XbbException 业务异常
     */
    Integer updateBatch(List<UpdateDataEntity> updateList, String corpid, WriteRequest.RefreshPolicy refreshPolicy) throws XbbException;
    /**
     * 批量删除
     * @author 吴峰
     * @date 2019/3/7 19:51
     * @param idIn 采购合同id列表
     * @param corpid 公司id
     * @return java.lang.Integer
     * @throws XbbException 业务异常
     */
    Integer deleteBatch(List<Long> idIn, String corpid) throws XbbException;

    /**
     * 单个删除
     * @param id
     * @param corpid
     * @return
     * @throws XbbException
     */
    Integer deleteByKey(Long id,String corpid) throws XbbException;

    /**
     * 获取智能助手需要的采购合同数据
     *
     * @param corpid 公司id
     * @param idIn 数据ids
     * @return
     * @throws
     * @author hongxiao
     * @date: 2020-02-24 16:56
     * @since v4.13.0
     * @version v4.13.0
     */
    List<AiPurchaseEntity> getPurchaseList4Ai(String corpid, List<Long> idIn);


    /**
     * Description: 根据采购合同id批量获取合同data字段中的某个值
     * @param corpid 公司id
     * @param purchaseIds 合同ids
     * @return java.util.List<java.lang.String>
     * @author 魏荣杰
     * @date 2019/4/3 15:53
     * @since v1.0
     */
    List<String> getPurchaseJsonExtractListByIn(String corpid, List<String> purchaseIds, String attr);

    /**
     * 批量获取合同
     * @param corpid
     * @param idIn
     * @return
     */
    List<PurchaseEntityExt> getPurchaseListByIdIn(String corpid,List<Long> idIn);

    List<String> getCorpidList();

    List<PurchaseEntityExt> findEntitysWithoutSub(Map<String, Object> param);

    /**
     * 编辑时格式化解释
     *
     * @param formatExplainDTO 入参
     * @throws XbbException 异常
     * @author Jian.Wang
     * @date 2019-02-25 21:23
     */
    void formatUpdateExplain(FormatExplainDTO formatExplainDTO) throws XbbException;
    /**
     * 新建时格式化解释
     *
     * @param formatExplainDTO 入参
     * @throws XbbException 异常
     * @author long.rao
     * @date 2019-02-13 20:53
     */
    void formatAddExplain(FormatExplainDTO formatExplainDTO) throws XbbException;

    /**
     * 采购合同编辑格式化数据格式
     *
     * @param saasAnalysisDataDTO saas编辑数据
     * @throws XbbException 参数格式错误异常
     * @param result 要返回的jsonobject
     * @author Jian.Wang
     * @date 2019/1/23 20:00
     * @since v1.0
     **/
    void formatData(SaasAnalysisDataDTO saasAnalysisDataDTO, JSONObject result) throws XbbException;

    void getProductList(Boolean forLinkAdd, String corpid, List<PurchaseProductEntity> purchaseProductEntityList, JSONObject dataObject, Map<Long, ProductEntityExt> productMap) throws XbbException;

    void formatProduct4Show2(Long dataId, String corpid, JSONObject data, UpdateDataTypeEnum updateDataTypeEnum) throws XbbException;

    /**
     * 解析单个产品
     * @param entity
     * @return
     */
    JSONObject formatSingleProduct(PurchaseProductEntity entity);

    Integer updateTime(Long id,String corpid) throws XbbException ;
}
